<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	String lastPage = "/index";
	if(null != session.getAttribute("page") && !"".equals(session.getAttribute("page"))) {
		lastPage = session.getAttribute("page").toString();
		session.removeAttribute("page");
	}
%>
<!doctype html>

<!--告诉浏览器当前网页使用的是中文，声明后将有便于外部程序对网页进行翻译，例如有道翻译等等-->
<html lang="zh-CN">

<head>

<!--编码格式为 utf-8(国际编码)-->
<meta charset="utf-8">

<!--设置页面关键字-->
<meta name="keywords" content="设置网站关键字">

<!--设置页面的描述-->
<meta name="description" content="设置页面的描述,建议在200字以内">

<!--设置浏览器优先使用急速模式-->
<meta name="renderer" content="webkit">

<!--禁止移动设备UC浏览器对字体大小的控制-->
<meta name="wap-font-scale" content="no">

<!--告诉IE使用最新的引擎渲染网页，chrome=1则可以激活Chrome Frame(谷歌浏览器内嵌框架)-->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<!--建立一个视觉窗口, 可视区域宽度等于设备宽度, 初始缩放比例为1倍, 最小缩放比例为1倍, 最大缩放比例为1倍, 禁止用户进行缩放-->
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">

<title>登陆页</title>

<link rel="stylesheet" href="<%=basePath%>css/zhicwl.css">
<link rel="stylesheet" href="<%=basePath%>css/zhicwl-bj.css">
<link rel="stylesheet" href="<%=basePath%>css/zhicwl-zj.css">

<script src="<%=basePath%>js/fontSize.js"></script>
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>

<link rel="stylesheet" href="<%=basePath%>plugins/layer/mobile/need/layer.css"/>
<script src="<%=basePath%>plugins/layer/mobile/layer.js"></script>

<style>
html, body{ height: 100%;}
body{
	display: box; 
	display: -webkit-box; 
	display: -moz-box; 
	box-align:center;
	-webkit-box-align:center; 
	-moz-box-align:center;
}
</style>

</head>

<body>
<article class="dlmart">
  <section>
  	<c:choose>
  		<c:when test="${empty wx_id or wx_id == 0}">
    		<h2 class="fontsize-15 padding-lr-15">已有寻宝帐号？</h2>
   		</c:when>
   		<c:otherwise>
    		<div class="yhtouds">
		  	<c:choose>
				<c:when test="${empty headimgurl}"><img src="<%=basePath%>images/img51.png"></c:when>
				<c:otherwise><img src="${headimgurl}"></c:otherwise>
			</c:choose>
			<h2 class="fontsize-15 padding-lr-15"><span class="color2">亲爱的微信用户：</span> ${nickname}</h2>
		  	</div>
   		</c:otherwise>
   	</c:choose>

    <form class="dlzc-form" onsubmit="return false">
    <input type="hidden" id="wx_id" value="${wx_id}">
      <div class="height1"></div>
      <section class="dlzc-form-input padding-lr-15 overflow-hidden">
        <img src="<%=basePath%>images/img01.png">
        <p><input name="phone" id="phone" type="number" placeholder="手机号/邮箱" autocomplete="off"></p>   
      </section>
      <section class="dlzc-form-input padding-lr-15">
		<img src="<%=basePath%>images/img02.png">
        <p><input name="password" id="password" type="password" placeholder="登录密码"></p>
      </section>
      
      <div class="height1"></div>
      <div class="padding-lr-15 margin-top-15">
      	<button type="submit" id="login_BTN" class="zhicwl-btn">
      	<c:choose>
      		<c:when test="${empty wx_id or wx_id == 0}">登录</c:when>
      		<c:otherwise>登录并绑定微信</c:otherwise>
      	</c:choose>
      	</button>
      </div>
    </form>

    <div class="padding-lr-15 margin-top-15 overflow-hidden">
      <a class="float-left color1" href="<%=basePath%>register.jsp">立即注册</a>
      <a class="float-right color1" href="<%=basePath%>change_password.jsp">忘记密码？</a>
    </div>
  </section>
  
  <c:if test="${empty wx_id or wx_id == 0}">
	  <section class="margin-top-45 padding-lr-15">
	    <h2 class="fontsize-15">没用寻宝帐号？ <span class="color2">海量产品！</span> <span class="color2">免费兑换！</span></h2>
	    <div class="weixzh margin-top-15"><button type="button" onclick="oauth2()" class="zhicwl-btn">使用微信帐号</button></div>
	  </section>
  </c:if>
</article>

<script src="<%=basePath%>js/zhicwl.js"></script>
<script type="text/javascript">
	var ctx = "${pageContext.request.contextPath}";
	$(function() {
		$("#login_BTN").on("click",function(){
			$(this).attr("disabled", true);
			login();
		});
	});
	
	// 登录
	function login() {
		var phone = $("#phone").val();
		var password = $("#password").val();
		if (null == phone || phone == "") {
			layer.open({
				content: "手机号码不能为空",
				skin: 'msg',
				time: 2, //2秒后自动关闭
				end:function(){
					$("#login_BTN").removeAttr("disabled");
					$("#phone").focus();
				}
			});
			return;
		} else if(!(/^1[34578]\d{9}$/.test(phone))){
	        layer.open({
				content: "手机号码有误，请重填",
				skin: 'msg',
				time: 2, //2秒后自动关闭
				end:function(){
					$("#login_BTN").removeAttr("disabled");
					$("#phone").focus();
				}
			});
	        return;
	    }
		
		if (null == password || password == "") {
			layer.open({
				content: "登录密码不能为空",
				skin: 'msg',
				time: 2, //2秒后自动关闭
				end:function(){
					$("#login_BTN").removeAttr("disabled");
					$("#password").focus();
				}
			});
			return;
		}
		
		var li = layer.open({type: 2});
		$.ajax({
	        type : "post",  
	        url : ctx+"/member/u/login",
	        dataType:"json",
	        data: {
	        	phone : $('#phone').val(),
	        	password : $('#password').val(),
	        	wx_id : $('#wx_id').val()
	        },
	        success : function(msg) {
	        	layer.close(li);
	        	layer.open({
 					content: msg.msg,
 					skin: 'msg',
 					time: 1, //2秒后自动关闭
 					end:function(){
 						$("#login_BTN").removeAttr("disabled");
 						if (msg.code == 0) {
 							var url = "/index";
 							var lastPage = "<%=lastPage%>";
 							if (null != lastPage && lastPage != "") {
 								url = ctx+lastPage;
 							}
 			        		window.location.href = url;
 			        	}
 					}
 				});
	        }
	    });
	}
	function oauth2() {
		var redirect_uri = encodeURIComponent("http://www.xunbaoo.com/redPacket/wx/oauth");
		var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc6dc67749e9e5ba8&redirect_uri="+redirect_uri+"&response_type=code&scope=snsapi_userinfo&connect_redirect=1&state=STATE#wechat_redirect";
		window.location.href = url;
	}
</script>
</body>
</html>